use axum::extract::Path;
use axum::http::StatusCode;
use axum::response::IntoResponse;

pub async fn run_strategy(Path(name): Path<String>) -> impl IntoResponse {
    tracing::info!("execute strategy : {name}");
    let execute_result = match name.as_str() {
        "avg_by_province" => sq_strategy::biz::avg_by_province::run().await,
        "cons5d_diff_cons10d" => sq_strategy::biz::cons5d_diff_cons10d::run().await,
        "cons7d_1pct_streak" => sq_strategy::biz::cons7d_1pct_streak::run().await,
        "extreme_pct_chg" => sq_strategy::biz::extreme_pct_chg::run().await,
        "longest_rising_streak" => sq_strategy::biz::longest_rising_streak::run().await,
        _ => {
            return (
                StatusCode::BAD_REQUEST,
                format!("unknown strategy name: {}", name),
            );
        }
    };

    match execute_result {
        Ok(msg) => {
            sq_wecom::notify_all(&msg, &["ShuiTongYaoNanHai", "DaPengCheng"]).await;
            (StatusCode::OK, "操作成功！".into())
        }
        Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
    }
}
